package createThread;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**这个有问题  不知道为什么
 * @program: jvm
 * @description
 * @author: tkk fendoukaoziji
 * @create: 2019-04-09 13:45
 **/
public class TwoThreadDeleteList2 {
    public static void main(String[] args) {
        Integer[] array = {0, 1, 2, 3};
        ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(array));

        ExecutorService executors = Executors.newFixedThreadPool(2);
        while(list.size()>0){
            System.out.println(list.size());
            synchronized (list){
                Integer integer = list.get(0);
                System.out.println(integer);
                executors.submit(new MyListThread(integer));
                list.remove(integer);
            }
        }
        //关闭线程池
        executors.shutdown();
    }
    public static class MyListThread implements Runnable{
        public Integer i;
        public MyListThread(Integer i){
            this.i=i;
        }

        public void run(){
            System.out.println(Thread.currentThread().getName()+"is running ");
            System.out.println("当前list第一个数值"+i);
        }
    }

}
